package com.gjm.demo.bean;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Controller;

@Controller
public class StudentBean {

//    @Primary
    @Bean
    public String setName1() {
        return "王五";
    }

    @Bean
    public String setName2() {
        return "赵六";
    }

//    @Bean
//    @Primary
    @Bean(name = {"student1", "student2"})
//    @Bean({"student1, student2"})
    public Student getStudent1() {
        return new Student("张三", 12);
    }

//    @Primary
    @Bean
    public Student getStudent2() {
        return new Student("李四", 15);
    }

    @Bean
    public Student getStudent3(@Qualifier("setName2") String name) {//使用带有参数的方法，spring会查询有没有name类型的对象(有且只有一个)，若有就赋值，若没有就报错
        return new Student(name, 11);
    }
}
